<template>
	<view>
		<view class="cu-bar bg-white sticky">
			<view class="action">
				<text @tap="back" class="cuIcon-back text-gray"></text> 
			</view>
			<view class="content text-bold">
				金币收益
			</view>
			<view class="action">
				<text class="text-green" @tap="record">提现记录</text>
			</view>
		</view>
		<view class="padding flex">
			<view class="flex-twice padding-top-xs padding-left ">
				<view class="text-bold text-lg">
					当前金币：{{currentCreditNum}}
				</view>
				<view class="margin-top-sm text-gray text-sm">
					1个金币相当于1元人民币
				</view>
			</view>
			<view class="flex-sub">
				<button class="cu-btn bg-green" @tap="crash">提现</button>
			</view>
		</view>
		<scroll-view scroll-y style="height: calc(100vh - 175px);" @scrolltolower="loadMore">
			<view class="padding bg-white flex margin-sm bg-white" v-for="(item,index) in list.rows" :key="index">
				<view class="flex-treble">
					<view class="text-black">{{item.sourceDesc}}</view>
					<view class="padding-top text-gray text-sm">{{item.creTm}}</view>
				</view>
				<!-- class="cu-btn orange block"  :class="[item.checked?'bg-orange':'line-orange']"    @click="ChooseCheckbox(item)" -->
				<view class="flex-sub text-lg padding-top text-center" :class="[item.entryType=='1'?'text-orange':'']">
					{{item.entryType=='1'?'+':'-'}}{{ parseInt(item.goldCoinNum) }}
				</view>
			</view>
			
			<view v-if="isLoad" class="cu-load text-gray loading"></view>
			<view v-else-if="list.rows.length < list.total" class="cu-load text-gray">已加载</view>
			<view v-else-if="list.rows.length==list.total && list.total!=0" class="cu-load text-gray over"></view>
			<view v-else="list.total==0" class="margin-top padding-top text-center text-gray">
				<text class="cuIcon-activityfill" style="font-size: 30px;"></text>
				<view class="">
					暂无收益记录
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {rows: [], total: 0},
				queryData: {
					currPage: 1,
					pageSize: 10,
					entryType: '1'
				},
				currentCreditNum: 0,
				isLoad: true,
			};
		},
		onLoad() {
			// this.getList();
		},
		onShow() {
			this.getList();
		},
		methods: {
			record(){
				uni.navigateTo({
					url: '/pages/user/cashcord'
				})
			},
			back(){
				uni.navigateBack({
					
				})
			},
			crash() {
				if (this.currentCreditNum < 15) {
					uni.showModal({
						title: '提示',
						content: '不满15金币不能提现，成为合伙人邀请好友获得金币',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/user/intepage'
								})
							} else if (res.cancel) {}
						}
					});
					return;
				}
				uni.navigateTo({
					url: '/pages/user/crash?currentCreditNum=' + this.currentCreditNum,
				});
			},
			loadMore() {
				if(this.list.rows.length == this.list.total){
					return;
				}
				this.isLoad = true;
				let _this = this;
				setTimeout(() => {
					_this.queryData.currPage += 1;
					_this.getList();
				}, 500);
			},
			getList() {
				this.loadingStatus = 'loading';
				let _this = this;
				this.baseRequest('api/driver/goldcoin/log', 'GET', this.queryData, function(res, info) {
					_this.isLoad = false;
					_this.showRefresh = false;
					if (res) {
						_this.currentCreditNum = res.otherInfo ? res.otherInfo.currentCreditNum : 0;
						if (res) {
							if (_this.queryData.currPage != 1) {
								_this.list.rows = _this.list.rows.concat(res.rows);
								_this.list.total = res.total;
							} else {
								_this.list = res;
							}
						} else {
							if (_this.queryData.currPage != 1) {
								return;
							}
							_this.list = {
								total: 0,
								rows: []
							};
						}
					}
				});
			},
		}
	}
</script>

<style>
	page {
		padding-bottom: 100upx;
	}
</style>
